﻿using System;
using fastCSharp.net;
using fastCSharp;
using fastCSharp.code.cSharp;

namespace diantou.web.ajax
{
    /// <summary>
    /// 用户公共操作
    /// </summary>
    [fastCSharp.code.cSharp.ajax(IsPool = true)]
    class userPub : userHandle<userPub>
    {
        /// <summary>
        /// 编辑框标题抓取任务池
        /// </summary>
        private static readonly htmlTitleClient.task titleCrawler = new htmlTitleClient.task(128);
        /// <summary>
        /// 根据URL抓取标题
        /// </summary>
        /// <param name="link"></param>
        /// <param name="onReturn"></param>
        public void EditorGetLink(string link, Action<returnValue<string>> onReturn)
        {
            titleCrawler.Get(link, value => onReturn(value));
        }
        /// <summary>
        /// 上传编辑框粘帖图片
        /// </summary>
        /// <param name="identity"></param>
        /// <returns></returns>
        public string[] EditorUploadPasteImage(ref int identity)
        {
            string[] fileNames = null;
            if (currentUser != null)
            {
                int count = 0;
                fileNames = new string[form.Files.Count];
                foreach (fastCSharp.net.tcp.http.requestForm.value file in form.Files)
                {
                    string fileName = upload.LoadImage(WorkPath, file);
                    fileNames[count++] = fileName == null ? null : fileName.Substring(WorkPath.Length).replace('\\', '/');
                }
            }
            return fileNames;
        }
        static userPub()
        {
            if (fastCSharp.config.appSetting.IsCheckMemory) checkMemory.Add(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        }
    }
}
